package com.bdzt.beidoubox.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bdzt.beidoubox.R;
import com.bdzt.beidoubox.entity.ScanBoxResultBean;

import java.util.List;

/**
 * Author： 默小二
 * E-mail: dear_mic@yeah.net
 * Date:  4/5/2017 5:19 PM.
 * Desc:
 */

public class ScanResultAdapter extends BaseAdapter {
    private Context context;
    private List<ScanBoxResultBean> data;
    private LayoutInflater inflater;

    public ScanResultAdapter(Context context, List<ScanBoxResultBean> da) {
        this.context = context;
        this.data = da;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null || view.getTag() == null) {
            holder = new ViewHolder();
            view = inflater.inflate(R.layout.gridviewitem, viewGroup, false);
            holder.scanTitle = (TextView) view.findViewById(R.id.tv_gridTitle);
            holder.scanDate = (TextView) view.findViewById(R.id.tv_gridDate);
            holder.scanLongitude = (TextView) view.findViewById(R.id.tv_gridLongitude);
            holder.scanLatitude = (TextView) view.findViewById(R.id.gridLatitude);
            holder.scanDirection = (TextView) view.findViewById(R.id.tv_gridDirection);
            holder.scanDistance = (TextView) view.findViewById(R.id.tv_gridDistance);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.scanTitle.setText(data.get(i).getTitle());
        holder.scanDate.setText(data.get(i).getDate());
        holder.scanDirection.setText(data.get(i).getDirection());
        holder.scanDistance.setText(data.get(i).getDistance());
        holder.scanLongitude.setText(data.get(i).getLongitude());
        holder.scanLatitude.setText(data.get(i).getLatitude());

        return view;
    }

    class ViewHolder {
        private TextView scanTitle;
        private TextView scanDate;
        private TextView scanLongitude;
        private TextView scanLatitude;
        private TextView scanDirection;
        private TextView scanDistance;
    }
}
